<template>
    <el-dialog title="上报年报详情" :visible.sync="open" width="65%" append-to-body :before-close="closeDelDialog">

        <el-row :gutter="10" class="mb8" ref="refbut">
            <el-col :span="1.5">
                <!-- v-hasPermi="['tenantManage:templateManage:basicData:add']" -->
                <el-button type="primary" plain icon="el-icon-plus" @click="hznb">汇总年报</el-button>
                <!--<el-button type="primary" plain icon="el-icon-plus" @click="addtjTap">根据检索条件添加</el-button>-->
            </el-col>

        </el-row>
        <el-table :data="tableData" height="400" border style="width: 100%">
            <!--<el-table-column type="selection" width="50" align="center" header-align="center">
            </el-table-column>-->
            <el-table-column type="index" label="序号">
            </el-table-column>
            <!--<el-table-column prop="date" label="档案类型">
                <template slot-scope="scope">
                    {{ datmInfo.categoryName }}
                </template>
            </el-table-column>-->
            <el-table-column prop="registeredUnit" label="注册单位" width="300">
            </el-table-column>
            <el-table-column prop="registeredPerson" label="注册人" width="300">
            </el-table-column>
            <el-table-column prop="userName" label="用户名">
            </el-table-column>
            <el-table-column prop="remark" label="描述">
            </el-table-column>
            <el-table-column  label="操作">
              <template slot-scope="scope">
                <el-button type="success" plain @click="onPreviewTap(scope.row)">查看</el-button>
               <!-- <el-button type="danger" plain @click="handleDelete(scope.row)">上传</el-button>-->
                <el-upload class="upload-file-demo" action="上传的url" ref="annualUpload" :auto-upload="true"
                           :show-file-list=false :accept="accept" :http-request="annualFile" :limit="1" :before-upload="beforeUpload"
                           :file-list="annualFileList">
                    <el-button type="primary" icon="el-icon-upload" @click="onPreviewTap1(scope.row)">上传</el-button>
                </el-upload>
              </template>
            </el-table-column>


            <!--<el-table-column prop="IS_OPENS" label="开放属性">
                <template slot-scope="scope">
                    <span v-for="(i, idx) in dict.type.IS_OPENS" :key="idx">
                        {{ scope.row.IS_OPENS == i.value ? i.label : '' }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column prop="MJ" label="密级">
              <template slot-scope="scope">
                    <span v-for="(i, idx) in dict.type.MJ" :key="idx">
                        {{ scope.row.MJ == i.value ? i.label : '' }}
                    </span>
              </template>
            </el-table-column>
            <el-table-column prop="BZ" label="备注">
            </el-table-column>-->
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="daListPost" />


      <el-dialog :title="viewTitle" :visible.sync="viewOpen" width="45%" append-to-body>
        <div>
          <!--
           文件预览
           1、修改添加文件预览istype="1"
           2、查看组件详情istype="2"
           -->
          <FilePreview v-if="item" :item="item" :istype="istype" :moudle="1"></FilePreview>
        </div>
      </el-dialog>
    </el-dialog>


</template>
<script>

//import { daList, addDaToFangan, addAllDaToFangan } from "@/api/archive/filesManage/editReleaseManage.js" E:\workspace_qhjk_syd\qhjk\yuanqiao-ui\src\api\archive\supervision\annualInspectionNotice.js
import { findNoticeList,yearReportCount,checkIsUpload} from "@/api/archive/supervision/annualInspectionNotice.js"
import FilePreview from "@/views/archive/supervision/supervises/filePreview";
import { uploadFile } from "@/api/archive/supervision/annualInspectionNotice";
export default {
    props: ["open", "datmInfo"],
    components: { FilePreview },
    archive_Dicts: ['IS_OPENS','MJ'],
    watch: {
        datmInfo: {
            handler(val) {
                console.log(val)
                this.queryParams["noticeId"] = val.id;
                this.queryParams["year"] = val.year;
                //this.queryParams["fabuWangduan"] = val.fabuWangduan;
                //this.queryParams["fabuFangshi"] = val.fabuFangshi;
                this.daListPost();
            },
            immediate: true
        }
    },
    data() {
        return {
            queryParams: {
                pageNum: 1,
                pageSize: 10,

            },
          tenantNoticeId:'',
            accept: '.xls, .xlsx',
            annualFileList: [],
            istype: '1',
            item: '',
            viewOpen: false,
            viewTitle: '',
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            dateRange: [],
            tableData: [],
        }
    },
    created() {
      //daListPost();
    },
    methods: {
      hznb(){
        this.$message.success('已开始汇总');
        console.log('llll',this.queryParams)
        yearReportCount(this.queryParams.noticeId,this.queryParams.year).then(res => {
          if (res.code == "200") {

          }
        })
      },
      annualFile(content) {
        this.file = content.file
        const formData = new FormData();
        formData.append("file", content.file);
        formData.append("type", '-1');
        formData.append("id", this.tenantNoticeId);
        if(this.fileMJ){
          formData.append("mj", this.fileMJ);
        }

        uploadFile(formData).then(response => {
          if (response.code == "200") {
            this.$message.success('上传成功');
          }
          this.annualFileList = [];
          // this.annualFileList.push({
          //   filePath: response.data.filePath,
          //   id: response.data.id,
          //   fileName: response.data.fileName,
          //   fileType: response.data.fileType,
          //   originalFile: response.data.originalFile,
          //   docType: this.getType(response.data.originalFile),
          //   mj: response.data.mj
          // })
        })
      },
      beforeUpload(file){ // 上传前 文件校验
        const extension = file.name.split('.')[1] === 'xls'
        const extension2 = file.name.split('.')[1] === 'xlsx'

        if (!extension && !extension2) {
          this.$message.warning('上传文件只能是 xls、xlsx格式!')
          return false;
        }
        //return false; // 返回false不会自动上传
      },
      // 预览
      onPreviewTap(item) {
        checkIsUpload(item.id).then(res => {
          if (res.code == "200") {
            this.viewTitle = "查看";
            this.viewOpen = true
            this.item = item
            this.item.isdownloadFile2 = "1"
            this.item.docType = 'XLSX'
          }

        })

      },
      onPreviewTap1(item) {
        this.tenantNoticeId = item.id;

      },
        //档案条目查询列表
        daListPost() {
        let tempYear = this.queryParams.year;
          this.queryParams.year = null;
          findNoticeList(this.queryParams).then(res => {
                if (res.code == "200") {
                    this.total = res.total;
                    this.tableData = res.rows
                }

            })
          this.queryParams.year = tempYear;
        },

        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.ID)
            this.single = selection.length !== 1
            this.multiple = !selection.length

        },
        //添加档案条目查询
        addTap() {
            console.log(this.ids, this.single, this.multiple, "0000")
            if (this.multiple) {
                this.$message({ message: "请选择档案", type: 'warning' })
                return
            }
            addDaToFangan({
                "subTableName": this.datmInfo.subTableName,
                "categoryName": this.datmInfo.categoryName,
                "fanganId": this.datmInfo.id,
                "ids": this.ids
            }).then(res => {
                console.log(res, "-----------------------------------------------")
                if (res.code == "200") {
                    this.$message({ message: "添加成功", type: "success" })
                }
            })

        },

        //根据检索条件添加
        addtjTap() {



            var data = {
                subTableName: this.queryParams.subTableName,    //必填
                fabuWangduan: this.queryParams.fabuWangduan,//必填
                fabuFangshi: this.queryParams.fabuFangshi,//必填
                categoryName: this.datmInfo.categoryName,
                fanganId: this.datmInfo.id,
                title: this.queryParams.title,
                dh: this.queryParams.dh,
                zrz: this.queryParams.zrz,
                is_opens: this.queryParams.is_opens,
                rq: this.queryParams.rq,
                rq2: this.queryParams.rq2
            }

            addAllDaToFangan(data).then(res => {

                if (res.code == "200") {
                    this.$message({ message: "添加成功", type: "success" })
                }
            })
        },

        //关闭
        closeDelDialog() {

            this.$emit("closeDelDialog")
        },
        //搜索
        handleQuery() {
          if(this.dateRange != null) {
            if(this.dateRange.length != 0) {
              this.queryParams["rq"] = this.dateRange[0]
              this.queryParams["rq2"] = this.dateRange[1]
            }
          } else {
            this.queryParams["rq"] = undefined
            this.queryParams["rq2"] = undefined
          }
            this.daListPost();
        },
        //重置
        resetQuery() {
            this.reset();
        },

        reset() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 10,
                title: undefined,
                dh: undefined,
                zrz: undefined,
                is_opens: undefined,
                rq: undefined,
                rq2: undefined,
                subTableName: this.datmInfo.subTableName,
                fabuWangduan: this.datmInfo.fabuWangduan,
                fabuFangshi: this.datmInfo.fabuFangshi
            }
            this.dateRange = [];
            this.daListPost();
        }
    }
}
</script>
<style lang="scss" scoped></style>
